package com.example.springbootdemo.config;

import com.xhs.miniapp.api.XhsMaService;
import com.xhs.miniapp.api.impl.XhsMaServiceImpl;
import com.xhs.miniapp.config.impl.XhsMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author ws
 * @create 2025/7/24 15:49
 */
@Configuration
@EnableConfigurationProperties(XhsMaProperties.class)
public class XhsMaConfiguration {

    private final XhsMaProperties properties;

    @Autowired
    public XhsMaConfiguration(XhsMaProperties properties) {
        this.properties = properties;
    }

    @Bean
    public XhsMaService wxMaService() {
        XhsMaService maService = new XhsMaServiceImpl();
        XhsMaDefaultConfigImpl config = new XhsMaDefaultConfigImpl();
//        XhsMaDefaultConfigImpl config = new XhsMaRedisConfigImpl(jedisPool);
        // 使用上面的配置时，需要同时引入jedis-lock的依赖，否则会报类无法找到的异常
        config.setAppid(properties.getAppid());
        config.setSecret(properties.getSecret());
        config.setToken(properties.getToken());
        config.setAesKey(properties.getAesKey());
        config.setMsgDataFormat(properties.getMsgDataFormat());
        //沙箱环境
        config.setApiHostUrl("https://miniapp-sandbox.xiaohongshu.com");
        maService.setWxMaConfig(config);
        return maService;
    }
}
